package com.mvc.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 8/29/12
 * Time: 12:20 PM
 */
public class ActionRequest {

    private Object controller;
    private Method controllerMethod;
    private HttpServletRequest request;
    private HttpServletResponse response;


    public ActionRequest(Object controller, Method controllerMethod) {
        this.controller = controller;
        this.controllerMethod = controllerMethod;

    }

    public Object getController() {
        return controller;
    }

    public Method getControllerMethod() {
        return controllerMethod;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public HttpServletResponse getResponse() {
        return response;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ActionRequest that = (ActionRequest) o;

        return !(controller != null ? !controller.getClass().equals(that.controller.getClass()) : that.controller != null) && !(controllerMethod != null ? !controllerMethod.equals(that.controllerMethod) : that.controllerMethod != null);

    }

    @Override
    public int hashCode() {
        int result = controller != null ? controller.getClass().hashCode() : 0;
        result = 31 * result + (controllerMethod != null ? controllerMethod.hashCode() : 0);
        return result;
    }


    public void setRequestAndResponse(HttpServletRequest request, HttpServletResponse response) {
        this.request = request;
        this.response = response;
    }

    void setController(Object controller) {
        this.controller = controller;
    }
}
